#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    printf("主线程(%d)开始执行...\r\n", getpid());
    pid_t pid = fork();
    if (pid == -1)
    {
        printf("子进程创建失败了。\r\n");
        return -1;
    }
    else if (pid == 0)
    {
        printf("子进程(%d)开始执行...\r\n", getpid());
        char *path = "other";
        char *argv[] = {path, "hahaha and heheda."};
        execve(path, argv, NULL);
        printf("指定程序执行失败...\r\n");
    }
    else
    {
        printf("父进程(%d)继续执行...\r\n", getpid());
        int status;
        waitpid(pid, &status, 0);
        printf("子进程(%d)执行完毕，退出码为%d。\r\n", pid, status);
    }
    printf("进程(%d)执行结束。\r\n", getpid());
    return 0;
}
